<?php

class Autoloader {

	private $_namespaces = array();

	public function register() {
        if (!function_exists('spl_autoload_register')) {
			throw new Exception('spl_autoload does not exist in this PHP version');
		}
		spl_autoload_register(array($this, 'autoload'));
    }
	public function autoload($class) {
		foreach($this->_namespaces as $namespace) {
			if (file_exists($namespace . $class . '.class.php')) {
				require_once($namespace . $class . '.class.php');
				return;
			}
		}
	}
	
	public function addNamespace($namespaceName, $namespacePath) {
		if (!is_string($namespaceName)) {
			throw new Exception('namespaceName parameter must be a String');
		};
		if (!is_string($namespacePath)) {
			throw new Exception('namespacePath parameter must be a String');
		};
		$this->_namespaces[$namespaceName] = $namespacePath;
	}

}

?>